package com.lht.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lht.admin.annotation.SysLog;
import com.lht.admin.utils.R;
import com.lht.admin.controller.AbstractController;
import com.lht.admin.entity.AssetsHouseInfoEntity;
import com.lht.admin.service.AssetsHouseInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 资产信息中的房产信息Controller
 *
 * @author ZhengZhanWu
 * @date 2019-12-29 20:23:30
 */
@RestController
@RequestMapping("/assetshouseinfo")
public class AssetsHouseInfoController extends AbstractController {
    @Autowired
    private AssetsHouseInfoService assetsHouseInfoService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("assetshouseinfo:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<AssetsHouseInfoEntity> list = assetsHouseInfoService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询资产信息中的房产信息
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("assetshouseinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        Page page = assetsHouseInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("assetshouseinfo:info")
    public R info(@PathVariable("id") Long id) {
        AssetsHouseInfoEntity assetsHouseInfo = assetsHouseInfoService.getById(id);

        return R.ok().put("assetshouseinfo", assetsHouseInfo);
    }

    /**
     * 新增资产信息中的房产信息
     *
     * @param assetsHouseInfo assetsHouseInfo
     * @return R
     */
    @SysLog("新增资产信息中的房产信息")
    @RequestMapping("/save")
    @RequiresPermissions("assetshouseinfo:save")
    public R save(@RequestBody AssetsHouseInfoEntity assetsHouseInfo) {

        assetsHouseInfoService.add(assetsHouseInfo);

        return R.ok();
    }

    /**
     * 修改资产信息中的房产信息
     *
     * @param assetsHouseInfo assetsHouseInfo
     * @return R
     */
    @SysLog("修改资产信息中的房产信息")
    @RequestMapping("/update")
    @RequiresPermissions("assetshouseinfo:update")
    public R update(@RequestBody AssetsHouseInfoEntity assetsHouseInfo) {

        assetsHouseInfoService.update(assetsHouseInfo);

        return R.ok();
    }

    /**
     * 根据主键删除资产信息中的房产信息
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除资产信息中的房产信息")
    @RequestMapping("/delete")
    @RequiresPermissions("assetshouseinfo:delete")
    public R delete(@RequestBody Long[] ids) {
        assetsHouseInfoService.deleteBatch(ids);

        return R.ok();
    }
}
